package com.xcity.game.task.detector;

import java.util.Collection;

import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Employee.State;
import com.xcity.game.task.Task;
import com.xcity.game.task.TaskDetector;
import com.xcity.game.task.TaskDetectorLabel;

/**
 * <pre>
 * 员工入驻
 * 1个参数:
 * 1.入驻员工数量
 * </pre>
 * @author yang.li
 *
 */
@TaskDetectorLabel(TaskDetector.TAKE_EMPLOYEE_IN_THE_BUILDING)
public class EmployeeEnterBuildTaskDetector implements TaskDetector {

	@Override
	public boolean isFinish(Task task) {
		int n = task.getTemplate().getConditions()[0];
		Collection<Employee> employees = task.getVm().getOwner().getEmployees().getEmployees();
		int c = 0;
		for (Employee employee : employees) {
			if (employee.getState() == State.DEFENSE && ++c >= n) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void onArchive(Task task, Object... vals) {
	}

}
